import 'package:manual/app.dart';
import 'package:manual/config/app_config.dart';
import 'package:manual/utils/logger.dart';
import 'startup_monitor.dart';
import 'package:flutter/material.dart';

class FxApplication {
  final StartupMonitor _monitor = StartupMonitor();

  FxApplication() {
    _monitor.mark("constructor");
  }

  Widget get app => const MyApp();

  AppStartRepository<AppConfig> get repository => const AppConfigRepository();

  Future<void> onLoaded(BuildContext context, int cost, AppConfig state) async {
    _monitor.mark("onLoadedStart");
    Logger.info("App startup loading completed in $cost ms", tag: "FxApplication");

    // Removed AppConfigBloc dependency
    Logger.info("Application state loaded successfully.", tag: "FxApplication");

    _monitor.mark("onLoadedEnd");
  }

  void onStartSuccess(BuildContext context, AppConfig state) {
    _monitor.mark("onStartSuccess");
    Logger.info("Application started successfully!", tag: "FxApplication");
    _monitor.logResults();
    // Removed page navigation logic
  }

  void onStartError(BuildContext context, Object error, StackTrace trace) {
    _monitor.mark("onStartError");
    Logger.error(
      "Error during application start.",
      tag: "FxApplication",
      error: error,
      stackTrace: trace,
    );
    _monitor.logResults();
    // Removed error page navigation logic
  }

  void onGlobalError(Object error, StackTrace stack) {
    _monitor.mark("onGlobalError");
    Logger.error(
      "Global error detected.",
      tag: "FxApplication",
      error: error,
      stackTrace: stack,
    );
  }
}
